package com.lt.flashcard.model.entity;

import org.bson.types.ObjectId;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Indexed;
import com.lt.flashcard.model.service.LearningService;
import com.lt.flashcard.model.service.Repository;

/**
 * The medal
 * @author ocsen
 *
 */
@Entity("medal")
public class Medal {

	@Id
	private ObjectId id;
	/**
	 * The name of medal
	 */
	@Indexed(unique=true)
	private String name;
	private int category = CATEGORY_STUDY;
	public static final int CATEGORY_STUDY = 0;
	public static final int CATEGORY_ACTIVITY = 1;
	public static final int CATEGORY_ACHIEVEMENT = 2;
	
	private String description = "";
	private String condition = "";
	
	private String largeThumbnail = "";
	private String smallThumbnail = "";
	private String focusThumbnail = "";
	//the order in the list
	private int weight = 0;
	
	private int visible = 1;
	
	public ObjectId getId() {
		return id;
	}
	
	public void setId(ObjectId id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public int getCategory() {
		return category;
	}
	
	public void setCategory(int category) {
		this.category = category;
	}
	
	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public String getCondition() {
		return condition;
	}
	
	public void setCondition(String condition) {
		this.condition = condition;
	}
	
	public String getLargeThumbnail() {
		return largeThumbnail;
	}
	
	public void setLargeThumbnail(String largeThumbnail) {
		this.largeThumbnail = largeThumbnail;
	}
	
	public String getSmallThumbnail() {
		return smallThumbnail;
	}
	
	public void setSmallThumbnail(String smallThumbnail) {
		this.smallThumbnail = smallThumbnail;
	}

	public String getFocusThumbnail() {
		return focusThumbnail;
	}

	public void setFocusThumbnail(String focusThumbnail) {
		this.focusThumbnail = focusThumbnail;
	}
	
	/**
	 * Count the percent of user that gained this medal
	 * @return
	 */
	public double countPercentUserGained() {
		LearningService lsrv = Repository.getInstance().getLearningService();
		return lsrv.countPercentUsersGainedMedal(this);
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public int getVisible() {
		return visible;
	}

	public void setVisible(int visible) {
		this.visible = visible;
	}
}
